:: ---------------------------------------------------------------------------------------
:: @title   project generator
:: @author  LuYao
:: @date    2024/03/09
:: @encode  GBK
:: @description     
::   1 generate project
::
:: ---------------------------------------------------------------------------------------


:: @echo off: close command print
:: rem and :: comment
@echo off & setlocal EnableDelayedExpansion

:: current directory
set PRO_PATH=!cd!

:: restore point
:loop_start
cd !PRO_PATH!

@echo. 
@echo. 
@echo current path: !cd!                                                                
@echo -----------------------------------------------------------------------------------
@echo        project generator                                 
@echo -----------------------------------------------------------------------------------
@echo  code    project                       code      project
@echo [031] jxtech031_blink                 [091] jxtech091_usart       
@echo [032] jxtech032_waterlight            [092] jxtech092_usart_recv           
@echo [033] jxtech033_buzzer                [093] jxtech093_usart_hex                   
@echo [034] jxtech034_keyled                [094] jxtech094_usart_txt               
@echo [035] jxtech035_ldr                   [101] jxtech101_i2c_mpu6050                           
@echo [041] jxtech041_oled                  [102] jxtech102_i2c_mpu6050                       
@echo [051] jxtech051_exti                  [103] jxtech103_i2c_24cxx                   
@echo [061] jxtech061_timer_it              [111] jxtech111_spi_w25qxx                       
@echo [062] jxtech062_timer_externalclk     [112] jxtech112_spi_w25qxx                       
@echo [063] jxtech063_timer_pwmled          [113] jxtech113_spi_tftlcd                           
@echo [064] jxtech064_timer_pwmservo        [121] jxtech121_bkp                           
@echo [065] jxtech065_timer_pwmmotor        [122] jxtech122_rtc                                   
@echo [066] jxtech066_timer_inputcapture1   [131] jxtech131_systemclk                                       
@echo [067] jxtech067_timer_inputcapture2   [132] jxtech132_mode_sleep                                       
@echo [068] jxtech068_timer_encoderspeed    [133] jxtech133_mode_stop                                       
@echo [071] jxtech071_adc_singlechannel     [134] jxtech134_mode_standby                                   
@echo [072] jxtech072_adc_multichannel      [135] jxtech135_mode_shutdown               
@echo [080] jxtech080_memory                [141] jxtech141_iwdg                           
@echo [081] jxtech081_dma                   [142] jxtech142_wwdg                           
@echo [082] jxtech082_dma_adc               [151] jxtech151_flash                                   
@echo.
@echo [1] generate all     [2] clean all    [0] exit
@echo.

set /p option=Input the code:
if 0 == !option! (
    goto :loop_exit
)

if 1 == !option! (
    FOR /F %%j IN ('progen list projects') DO (
        echo --------------- %%j ------------
        progen generate -t cmake    -v -p %%j
        progen generate -t uvision5 -v -p %%j
    )

    goto :loop_exit
)

if 2 == !option! (
    progen clean -t cmake
    progen clean -t uvision5

    goto :loop_start
)

set project=!option!
:loop_split
FOR /f "tokens=1,* delims= " %%a IN ("!project!") DO (
    FOR /F %%j IN ('progen list projects') DO (
        @echo %%j | findstr "%%a" > nul && (
            echo --------------- %%j -------------------
            progen generate -t cmake    -v -p %%j
            progen generate -t uvision5 -v -p %%j
        )
    )

    set project=%%b
    goto loop_split
)

goto :loop_start



:loop_exit